/**
* Project: Project1                                            
* Account: CS301003_18
* Author: Timothy N Tasse II
* Creation date: 10/01/2012                                   
* Completion time: 5+ Hours
*                                                              
* Honor Code: I pledge that this program represents my         
*   own program code. I received help from nobody  
*   in designing and debugging my program.                     
*/
package package1;

import java.util.ArrayList;


/**
 *
 * @author Timothy N Tasse II
 */
public class MyVector {
    private ArrayList<Double> vectorValues = new ArrayList<Double>();
    
    /**
     *
     * @param initValues
     */
    public MyVector(double [] initValues) {
        for (int i=0; i<initValues.length; i++) {
            vectorValues.add(initValues[i]);
        }
    }
    
    
    
    /**
     * 
     * @param incoming
     */
    public MyVector(MyVector incoming) {
        
        for (int i=0; i<incoming.vectorValues.size(); i++) {
            this.vectorValues.add( incoming.vectorValues.get(i) );
        }
    }
    
    /**
     * 
     * @param i
     * @return
     */
    public double get(int i) {
        return vectorValues.get(i);
    }
    
    /**
     * 
     * @return
     */
    public int size() {
        return vectorValues.size();
    }
    
    /**
     * 
     * @param incoming
     * @return
     */
    public MyVector plus(MyVector incoming) {
        double[] newVectorValues = new double[incoming.size()]; //Create new double array to pass to constructor
        
        for (int i=0; i<incoming.size();i++) {
            newVectorValues[i]=(this.get(i) + incoming.get(i));
        } //Loop through the incoming vector adding it to the same element of this. vector. Store it in the new double array
        return new MyVector(newVectorValues);
    }
    
    /**
     * 
     * @param incoming
     * @return
     */
    public MyVector minus(MyVector incoming) {
        double[] newVectorValues = new double[incoming.size()]; //Create new double array to pass to constructor
        
        for (int i=0; i<incoming.size();i++) {
            newVectorValues[i]=(this.get(i) - incoming.get(i));
        }//Loop through the incoming vector subtracting it from the same element of this. vector. Store it in the new double array
        return new MyVector(newVectorValues);
    }
    
    /**
     * 
     * @param scaler
     * @return
     */
    public MyVector scaledBy(double scaler)     {
        double[] newVectorValues = new double[this.size()]; //Create new double array to pass to constructor
        
        for (int i=0; i<this.size();i++) {
            newVectorValues[i]=(this.get(i) * scaler);
        }//Loop through this.vector multiplying it by the scaler. Store it in the new double array
        return new MyVector(newVectorValues);
    }
    
    /**
     *
     * @return 
     */
    @Override
    public String toString() {
        String output = "["; //Begin the output with a container character for better readability
        output += this.get(0); //Output the first element
        
        for (int i=1; i<this.size();i++) { //Continue looping through this vector.
            output += ", " + this.get(i); //Add a comma to the output following by a space and the element
        }
        output += "]"; //Output the last container character
        return output;
    }
    
    /**
     * 
     * @param incoming
     * @return
     */
    public boolean equals(MyVector incoming) {
        for (int i=0; i<this.size();i++) {
            if(this.get(i) == incoming.get(i)){ 
            } //Do nothing if the two are the same
            else {
                return false; //As soon as an element is not equal, return false and quit looping
            }
        }
        
        return true; //If false was not returned earlier, default to return true.
    }
    
    /**
     * 
     * @return
     */
    public MyVector abs(){
        double[] newVectorValues = new double[this.size()]; //Create new double array to pass to constructor
        
        for (int i=0; i<this.size();i++) { 
            newVectorValues[i]=(Math.sqrt(  Math.pow(this.get(i), 2)  )); 
        }
        return new MyVector(newVectorValues);
    }
    
    /**
     * 
     * @param incoming
     * @return
     */
    public double dot(MyVector incoming){
        double dotValue = 0;
        
        for (int i=0; i<this.size();i++) {
            dotValue+=(this.get(i) * incoming.get(i)); //Add a running total of this.vector element to the element of the incoming array
        }
        return dotValue;
    }
}
